-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhance INVALID_ARG_TYPE and cleanup some node:buffer error handling #14200
Conversation
throwNodeRangeError(lexicalGlobalObject, scope, "Invalid array length"_s); | ||
else | ||
throwTypeError(lexicalGlobalObject, scope, "Expected number"_s); | ||
const unsigned U32_MAX = std::numeric_limits<unsigned>().max(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constexpr
auto num = arg.asNumber(); | ||
if (num < 0 || std::isinf(num)) return Bun::ERR::OUT_OF_RANGE(scope, lexicalGlobalObject, name, 0, upperBound, arg); | ||
double intpart; | ||
if (std::modf(num, &intpart) != 0) return Bun::ERR::INVALID_ARG_TYPE(scope, lexicalGlobalObject, name, "integer"_s, arg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this supposed to truncate? if so std::trunc
might fit better
@@ -1527,6 +1478,9 @@ static inline JSC::EncodedJSValue jsBufferToString(JSC::VM& vm, JSC::JSGlobalObj | |||
if (UNLIKELY(length == 0)) { | |||
RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::jsEmptyString(vm))); | |||
} | |||
if (length > WTF::String::MaxLength) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have a different length constant for this?
RETURN_IF_EXCEPTION(scope, {}); | ||
} | ||
|
||
if (!lengthValue.isUndefined()) { | ||
end = parseIndex(lexicalGlobalObject, scope, lengthValue); | ||
end = parseIndex(lexicalGlobalObject, scope, "end"_s, lengthValue, limit - start); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
pulled out of #13757 to merge independently
wip: i expect having to update some test messages once this runs through the first time